package com.apes.fico.masterdata.gl.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * @program: apestech
 * @description: 科目组/科目类型
 * @author: Chengxm
 * @create: 2018-12-20 15:15
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = AccountingGroup.CONST_TABLE_NAME)
public class AccountingGroup extends Model {
    public final static String CONST_TABLE_NAME ="mas_acc_group";
    @Id
    @Column(name = "id", length = 8)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "科目组")
    @Comment("科目组编码")
    private String id;

    @Comment("科目组名称")
    @Column(name = "name", nullable = false, length = 64)
    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "acc_system_id", referencedColumnName = "id", nullable = false)
    @Comment("科目体系编码")
    private AccountingSystem accSystem;

    /*0:借:1:贷*/
    @Column(name = "balanorient", length = 1)
    @Comment("余额方向")
    @States(name = "余额方向", values = {
            @State(id = AccountingModel.DEBIT, name = "借方"),
            @State(id = AccountingModel.CREDIT, name = "贷方")})
    private String balanorient;

    /*左右0:左 1:右*/
    @Column(name = "balanposition", length = 1)
    @Comment("平衡公式位置")
    @States(name = "平衡公式位置", values = {
            @State(id = AccountingModel.LEFT, name = "左"),
            @State(id = AccountingModel.RIGHT, name = "右")
    })
    private String balanposition;

    @Column(name = "type")
    @Comment("科目类型性质")
    private int type;

//    public void setBalanorient(String balanorient) {
//        if (LogicalUtil.notIn(balanorient, AccountingModel.DEBIT, AccountingModel.CREDIT)) {
//            throw new RuntimeException("余额方向输入错误！");
//        }
//        this.balanorient = balanorient;
//    }

}
